function BuildingScene(){
	Scene.call(this);
	
	
	
	var _scene = new THREE.Scene();
	this.getScene = function(){return _scene;};
	
	this.objetos3D = {}; /* donde <id nivel> = "nombre Edifcio" + "nivel"*/
	this.insertedIds = {}; //id generado por el controller jerarquia. se usa para ver si un objeto(modelo) ya tiene su representacion(3d) en objetos3D
	this.deletedDanglingIds = {};
	var danglingPortals = {};
	
	
	
	
	this.getObjectBuilder = function(){}; //redefinida en las clases hijas
	
	//obj.IDJerarquia TODO
	this.addLevel = function(edificio, nivel, obj, id){
		this.insertedIds[id] = true;//TODO
		
		var id = ""+edificio+nivel;
		this.objetos3D[id] = obj;
		_scene.add(obj);
	}
	
	this.addObjToLevel = function(edificio, nivel, obj, id){
		this.insertedIds[id] = true;//TODO
		var idNivel = ""+edificio+nivel;
		var nivel3D = this.objetos3D[idNivel];
		
		if (!nivel3D){
			alert('error nivel 3d')
		}
		nivel3D.add(obj);
	}
	
	this.removeObjFromLevel = function(edificio, nivel, obj){
		
		var idNivel = ""+edificio+nivel;
		var nivel3D = this.objetos3D[idNivel];
		
		if (!nivel3D){
			alert('error nivel 3d')
		}
//		_scene.remove(obj);
		nivel3D.remove(obj);
	}
	
	
	this.addInterFloorDanglingPortal = function(edificio, nivel, obj, id, idModeloPortal){
		this.addObjToLevel(edificio, nivel, obj, id);
		danglingPortals[idModeloPortal] = obj;
		//obj.BuildingSceneID = id;
	}
	
	this.deletePortal = function(idModeloPortal){
		var oldObj = danglingPortals[idModeloPortal];
		if(oldObj){
			oldObj.parent.remove(oldObj);
		}
		this.deletedDanglingIds[idModeloPortal] = true;
		delete danglingPortals[idModeloPortal];
	}
	
	//ya no es mas dangling
//	params.sourceBuildingName = objeto.sourceSpace.piso.buildingName;
//	params.sourceLevel = objeto.sourceSpace.piso.level;
//	params.meshSource = meshSource;
//	params.idInterno = toRender[i].IDJerarquia;
//	params.idModeloPortal = objeto.id;
//	params.targetBuildingName = objeto.targetSpace.piso.buildingName;
//	params.targetLevel = objeto.targetSpace.piso.level;
//	params.meshSource = meshTarget;
	this.addInterFloorPortal = function(params){ 
		this.deletePortal(params.idModeloPortal);
		
		var newId = params.idInterno;
		this.addObjToLevel(params.sourceBuildingName, params.sourceLevel, params.meshSource, newId);
		this.addObjToLevel(params.targetBuildingName, params.targetLevel, params.meshTarget, newId);
	}
	
	this.addObjectToScene = function(obj){
		_scene.add(obj);
	}
	
	
	
	
	
	
	

	//-----------------------------------------------------------
	//---------------------- CREAR MUNDO ------------------------
	//-----------------------------------------------------------
	function crearMundo(scene){				

		//DEPRECATED
		/*
		if (DEBUGGING_DRAG) { //PARA DRAG
			var axes = new THREE.Axes();
			axes.scale.multiplyScalar(20);
			
			if (!SOMBRA) scene.add(axes);

			var geometry = new THREE.CubeGeometry( 140, 140, 140 );
			 objDrag = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xff0000 } ) );
			 scene.add( objDrag );
		}
		
		if (SOMBRA){ //SHADOOOOOOOOOWS
			var light = new THREE.SpotLight( 0xffffff, 0.07 );
			light.position.set( 0000, 5000, 000 );
			light.castShadow = true;
			scene.add( light );
		}
		
		//esto no se usa porque le sacamos las busquedas
		//creo las flechas y las agrego a la escena
		var loader = new THREE.JSONLoader();
		loader.createModel(UTILS.flechaData, function( geometry ) { 
			var mat1 =  new THREE.MeshLambertMaterial({ color: '0x00ff00'});
			var mat2 =  new THREE.MeshLambertMaterial({ color: '0xff0000'});
			_meshFlechaInicio = new THREE.Mesh( geometry, mat1 );
			_meshFlechaDestino = new THREE.Mesh(geometry, mat2);
			_meshFlechaInicio.visible = false;
			_meshFlechaDestino.visible = false;
			scene.add(_meshFlechaInicio);
			scene.add(_meshFlechaDestino);
			mat1 = mat2 = null;
		});
		
		
		if (SOMBRA){ //SHADOOOOOOOOOWS
			var light = new THREE.SpotLight( 0xffffff, 0.07 );
			light.position.set( 0000, 5000, 000 );
			light.castShadow = true;
			scene.add( light );
		}
		*/
		//FIN DEPRECATED
		
		
		var cubemap = THREE.ImageUtils.loadTexture('imagenes/sky2.jpg')
		var material = new THREE.MeshBasicMaterial( { color: 0xffffff, map: cubemap } )
		var geometry = new THREE.SphereGeometry( 100000, 100, 100 );

		var mesh = new THREE.Mesh( geometry, material );
		mesh.doubleSided = true;
		 mesh.position.y = 100000-10000;
		scene.add( mesh );
		
		 var plane = new THREE.Mesh(new THREE.PlaneGeometry(1000000, 1000000,1,1), new THREE.MeshBasicMaterial({
	            color: 0x333333
	        }));
		 plane.position.y = -500;
		 scene.add(plane)
		
		
		
		
		
	
		
		 
		
		if(CONSTANTS.MOSTRAR_ESCENA){
			
			var colores = ["0xff0000 ","0x00ff00 ","0x0000ff "];
			var colores = [new THREE.MeshLambertMaterial( { color: "0xffcc99"} ),
			               new THREE.MeshLambertMaterial( { color: "0x6699ff"} ),
			               new THREE.MeshLambertMaterial( { color: "0x99cc99"} ),
			               ];
			var count = 0;
			
			var loader = new THREE.SceneLoader();
	
			loader.load( "obj/escenauni.js", function(result){
				//console.log("result", result);
				var unMergedMeshes = [];
				for (var obj in result.objects){
					var malla = result.objects[obj]; 
					if (malla instanceof THREE.Mesh){
						
						//HACK: para pintar todos los autos de un color random
						if(malla.name.substring(4,0).toLowerCase() == "auto"){
							malla.geometry.materials[1] = new THREE.MeshLambertMaterial( { color: colores[count]} );
							count = (count + 1) % colores.length;
						}
						
					unMergedMeshes.push(malla);
						
					}
				}
				result.scene = null;
				result = null;
				
				var mergedGeo = new THREE.Geometry();
				for (var i = 0, l = unMergedMeshes.length; i<l; i++){	
					
					
					//HACK: para randomizar los colores de los autos
					if(unMergedMeshes[i].name.substring(4,0).toLowerCase() == "auto"){
	//					mergedMesh.geometry.materials[0] = MATERIAL_BUILDER.getMaterial("arrow_portal_externo");
						
						//var rand = "0x" + (Math.floor(Math.random()*16777215).toString(16));
						//console.log("rand", rand);
						//unMergedMeshes[i].geometry.materials[1] = new THREE.MeshLambertMaterial( { color: rand} );
						
						unMergedMeshes[i].geometry.materials[1] = colores[count];
						
						
	//							unMergedMeshes[i].geometry.materials[1] = new THREE.MeshLambertMaterial( { color: colores[count]} );
						//console.log("ntreeeeeeeeeeeeeeeeeeeeee", malla.name,colores[count]);
						count = (count + 1) % colores.length;
					}
					
					merge(mergedGeo, unMergedMeshes[i]);
					
				}
				var mergedMesh = new THREE.Mesh(mergedGeo, MaterialBuilder.MeshFaceMaterial);
				
				unMergedMeshes = null;
				unMergedMeshes = [];
				
				mergedMesh.rotation.x = -Math.PI/2;
				scene.add(mergedMesh);
			//	console.log("merged", mergedMesh);
				mergedGeo = null;
				escenaCompleta = mergedMesh ;
				mergedMesh = null;
				
			} );

		};

		
		var obj3D = new THREE.Object3D();
		obj3D.translateX(-450);//TODO
		
		//escena para el edificio de alem. TDOO esto esta harcodeado (habria que modularizarlo para los distintos edificios)
		var JSONloader =  new THREE.JSONLoader();
		JSONloader.load(  "obj/escena_solo_planos.js" , 
			function( geometry ) {	
			escenaPlanos = new THREE.Mesh(geometry, MaterialBuilder.MeshFaceMaterial);
			if (CONSTANTS.MOSTRAR_ESCENA) escenaPlanos.visible = false;
			
			if(SOMBRA){
				escenaPlanos.castShadow = true;
				escenaPlanos.receiveShadow = true;
			}
			obj3D.add(escenaPlanos);
			scene.add(obj3D);
			}
		);

		
		//TODO mostrar sprites en lugar de mallas 3d!!!
		if (true || CONSTANTS.MOSTRAR_TEXTO_3D){//var global
			
			var calles = [{name : "alem", position: {x: 963, y: -50  , z: 2270}},
			              {name : "cordoba", position: {x: -3246, y: -50  , z: -3048}},
			              {name : "12_de_octubre", position: {x: 1063, y: -50  , z: -7675}},
			              {name : "san_juan", position: {x: 5616, y: -50  , z: -3048}},
			              ]
			
			var params = {};
			var obj = null;
			for (var i = 0, l = calles.length; i < l; i++){
			//	var canvas = TEXTURE_BUILDER.neonLightEffect(calles[i].name);
			//	var canvas = TEXTURE_BUILDER.printText(calles[i].name);
			
				var map = THREE.ImageUtils.loadTexture( "imagenes/sprites/"+calles[i].name+".png" );
			//	var map = new THREE.Texture( canvas);
				map.minFilter = 6 //no quiero mip maps
					map.needsUpdate = true
				var obj = new THREE.Sprite( { map: map, useScreenCoordinates: false, /*color: 0xffffff*/ } );
				obj.scale.x = 3;
				obj.scale.y = 1.5;
				var posicion = calles[i].position; 
				obj.position.set( posicion.x, posicion.y+275,	posicion.z);
				scene.add(obj);
			}
			
		}
				
		//Tridente y grilla
		if (false){
			//Tridente
			var axes = new THREE.Axes();
			axes.scale.multiplyScalar(20);
			scene.add(axes);
			
			// Grid
			var geometry = new THREE.Geometry();
			geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( - 500, 0, 0 ) ) );
			geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( 500, 0, 0 ) ) );
				
			for ( var i = 0; i <= 20; i ++ ) {
				var line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.2 } ) );
				line.position.z = ( i * 50 ) - 500;
				scene.add( line );

				var line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.2 } ) );
				line.position.x = ( i * 50 ) - 500;
				line.rotation.y = 90 * Math.PI / 180;
				scene.add( line );
			}
		};
	}
	
	crearMundo(_scene);
}